import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Register from '@/pages/Register'
import Login from '@/pages/Login'
//保存一份push方法
let originPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location,resolve,reject) {
    //当传递了resolve和reject参数的时候调用原本的push函数，同时改变上下文对象
    if(resolve && reject){
        originPush.call(this,location,resolve,reject)
        // originPush.apply(this,[location,resolve,reject])
    }else{
        originPush.call(this,location,()=>{},()=>{})
    }
}
//保存一份replace方法
let originReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function (location,resolve,reject) {
    if(resolve && reject){
        originReplace.call(this,location,resolve,reject)
    }else{
        originReplace.call(this,location,()=>{},()=>{})
    }
}

export default new VueRouter({
    routes:[
        {
            path:"/",
            redirect:"/home",
            meta:{show:true}
        },
        {
            path:"/home",
            component:Home,
            meta:{show:true}
        },
        {
            path:"/search/:keyword?",
            name:"Search",
            component:Search,
            meta:{show:true}
        },
        {
            path:"/login",
            component:Login,
            meta:{show:false}
        },
        {
            path:"/register",
            component:Register,
            meta:{show:false}
        }
    ]
})